import com.pojo.TCustomer;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndJobsTest(){
        SqlSession session = MyBatisUtils.getSession();
        TCustomer customer = new TCustomer();
        customer.setUsername("jack");
        customer.setJobs("teacher");
        List<TCustomer> customers = session.selectList("com.mapper.TCustomerMapper.findCustomerByNameAndJobs",customer);
        for (TCustomer c : customers) {
            System.out.println(customer);
        }
        session.commit();
        session.close();
    }
    @Test
    public void updateCustomerBySet() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        TCustomer customer = new TCustomer();
        customer.setId(3);
        customer.setPhone("146133516");
        customer.setUsername("boy");
        int rows = sqlSession.update("com.mapper.TCustomerMapper.updateCustomerBySetTest", customer);
        if (rows > 0) {
            System.out.println("您成功修改了"+rows+"条数据");
        }else {
            System.out.println("执行修改操作失败！！！");
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findByArrayTest(){
        SqlSession sqlSession = MyBatisUtils.getSession();
        Integer [] roleIds = {2,3};
        List<TCustomer> customers = sqlSession.
                selectList("com.mapper.TCustomerMapper.findByArray",roleIds);
        for (TCustomer customer:customers){
            System.out.println(customers);
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findByListTest(){
        SqlSession session = MyBatisUtils.getSession();
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(2);
        List<TCustomer> customers =session.
                selectList("com.mapper.TCustomerMapper.find",ids);
        for (TCustomer customer : customers){
            System.out.println(customer);
        }
        session.close();
        session.commit();
    }
}
